#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import os
import time

def password():
    #password = getpass.getpass("Please input the administrator's password: ")
    return 'nvidia'

def get_ip():
    out_usb0 = os.popen("ifconfig | grep 'usb0'| cut -d, -f 3").read()
    ip_usb0 = out_usb0.split('\n')[0]
    out_usb1 = os.popen("ifconfig | grep 'usb1'| cut -d, -f 3").read()
    ip_usb1 = out_usb1.split('\n')[0]
    wireless_4gIP = os.popen("ifconfig | grep 'inet 10'").read()
    if ip_usb0 == 'RUNNING' or ip_usb1 == 'RUNNING':
        if wireless_4gIP != "":
            print("yes ping")
        else:
            print("no ping - inet 10")
            os.system("echo %s | sudo -S %s" % (password(),'/home/nvidia/HYSD_shell/gpio_436.sh'))
            time.sleep(30)
            os.system("echo %s | sudo -S %s" % (password(),'/home/nvidia/HYSD_shell/reset4g_count.sh'))
            os.system("echo %s | sudo -S %s" % (password(),'/home/nvidia/HYSD_shell/open4g.sh'))
    else:
        print("no ping - RUNNING")
        os.system("echo %s | sudo -S %s" % (password(),'/home/nvidia/HYSD_shell/gpio_436.sh'))
        time.sleep(30)
        os.system("echo %s | sudo -S %s" % (password(),'/home/nvidia/HYSD_shell/reset4g_count.sh'))
        os.system("echo %s | sudo -S %s" % (password(),'/home/nvidia/HYSD_shell/open4g.sh'))

res = get_ip()
